<?php


namespace app\api\controller\points;


use app\api\controller\Controller;
use app\api\model\user\Signin as SigninModel;

/**
 * 用户签到赠送积分
 * Class Signin
 * @package app\api\controller\points
 */
class Signin extends Controller
{
    /**
     * 本月签到记录
     */
    public function index()
    {
        $user = $this->getUser();
        $logs = SigninModel::month($user->user_id);
        return $this->renderSuccess(compact('logs'));
    }

    /**
     * 用户签到
     */
    public function create()
    {
        $user = $this->getUser();
        $today = SigninModel::getUserLog($user['user_id'], 'today');
        if ($today) {
            return $this->renderError('今天已经签到了，请明天再来');
        }
        $res = SigninModel::signin($user);
        return $res ? $this->renderSuccess() : $this->renderError('签到失败，请联系管理员');
    }

}